<?php
echo $javascript->link(array('front/jquery-ui-1.8.16.custom.min','popup/jquery.fancybox-1.3.4.pack'));
echo $this->Html->css(array('slider/jquery-ui-1.8.16.custom','front/jquery.fancybox-1.3.4'));
//debug($subjects);
//debug($adjectivelist); 
//debug($related_subjects);
?>

<script language="javascript">
    $(document).ready(function(){
        $('#SubjectViewForm').live('submit',function(){
        

            $.ajax({
                url: "rate",
                type: "POST",
                data: {
                    rating : $( "#slider-range-min" ).slider( "value" ),
                    id:$('#subject_id').val()
                },
                dataType: "html",
                async:false,
                success: function(res){
                   
                    var x=jQuery.trim(res);
                    if(x==''){
                       
                      
                        location.reload();

                    }else{
                        $("#registration_err").css("display","block");
                        $("#registration_err").html(x).delay(5000).fadeOut(1500);
                    }
                }
            });
            return false;
        });
       $('.report').live('click',function(){
       var title=$(this).attr('title');
       //alert(title);
       $('#reportImage').attr('title',title);
       });
       $("a.report").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false,
                'titleShow'     :false,
                'onClosed'		: function() {
	    $("#error").hide();
	}
                
	});
   
        
        
    });
</script>
<?php //debug($subjects);  ?>
<table id="table" width="100%">
    <tr>
        <td width="250px">
            <table width="200" >
                <tr>
                    <td> &nbsp; </td>
                </tr>
                <tr>
                    <td class="display-image">
                        <?php
                        $thumbnail = $this->PhpThumb->generate(
                                array(
                                    'save_path' => WWW_ROOT . 'img/uploads/Subjects/thumbs',
                                    'display_path' => 'uploads/Subjects/thumbs',
                                    'error_image_path' => 'noimage.png',
                                    'src' => WWW_ROOT . "img/uploads/Subjects/" . $subjects['Subject']['image'],
                                    'w' => 300,
                                    'h' => 350,
                                    'q' => 70,
                                    'zc' => 1
                                )
                        );
                        echo $this->Html->image($thumbnail['src'], array('width' => $thumbnail['w'], 'height' => $thumbnail['h']));
                        ?><a href="#inline1" id="various1" class="report mybutton" title="Image"><span id="image" class="report" >Report</span></a></td>
                </tr>
            </table>   
        </td>
        <td style="vertical-align: text-top">
            <table width="100%">
                <tr>

                    <td colspan="2"><h1><?php echo $subjects['Subject']['subject']; ?><?php
                        if (!empty($subjects['Subject']['desc'])) {
                            echo " <span style='padding-left:6px; font-size:18px;'>(" . $subjects['Subject']['desc'] . ")</span></h1>";
                        }
                        ?></h1><div class="clearfix"></div><a href="#inline1" id="various1" class="report mybutton" title="Title/Specifier"><span id="name" class=" report">Report</span></a></td>
                </tr> 
                <tr>
                    <td colspan="2">
                    <?php if(!empty($subjects['Subject']['redirects']))
                    
                    echo    $subjects['Subject']['redirects'] . " redirects here.";
                    ?>    
                     
                    </td>
                </tr>
                <tr>
                    <td><?php
                    if($subjects['Subject']['subject_id']!='0'){
                        
                    }
                    ?></td>
                    <td></td>
                </tr>
                <?php
                if (!empty($subjects['Subject']['tag_ids'])) {
                    foreach ($subjects['Subject']['tag_ids'] as $tag) {
                        ?>
                        <tr>
                            <td colspan="2"><?php
                echo '<span style="font-weight:bold;font-size:16px; margin-right:10px;">Tag Chain:</span>';
                echo "  " . $tag['tag'];
                        ?>
                            <a href="#inline1" id="various1" class="report mybutton" title="Tag"><span id="image" class="report">Report</span></a></td>
                        </tr> 
                        <?php if (in_array($tag['tag_id'], $subjects['Attribute'])) { ?>
                            <tr><td><fieldset>Attribute<table>
                                            <?php
                                            foreach ($subjects['Attribute'] as $attribute) {
                                                if ($attribute['tag_id'] == $tag['tag_id']) {
                                                    ?>

                                                    <tr>
                                                        <td><?php echo $attribute['attribute']; ?></td>
                                                        <td><?php echo $attribute['value']; ?></td>
                                                    </tr> 
                                                    <?php
                                                }
                                            }
                                            ?></table><a href="#inline1" id="various1" class="report mybutton" title="Attribute"><span id="image" class="report">Report</span></a></td></tr></fieldset>
                            <?php
                        }
                    }
                }
                ?>


                <tr>
                    <td id="label">Adjectives:</td>
                    <td style="padding-left: 22px" colspan="2"><span id="label" style="margin: 0px 20px 0px -12px;"></span><?php echo $subjects['Subject']['adjective_ids']; ?><a href="#inline1" id="various1" class="report mybutton" title="Adjective"><span id="image" class="report">Report</span></a></td>
                </tr>

                <?php if (!empty($subjects['SubjectRate'])) { ?>            
                    <tr>
                        <td id="label">No Of ratings :</td>
                        <td><?php $votes = count($subjects['SubjectRate']);
                echo $votes; ?></td>
                    </tr>
                    <tr style="height: 60px">
                        <td id="label">Avg. Rating :</td>
                        <td ><span class="rating"><?php
                        $rating = 0;
                        if ($votes == '0') {
                            $avg_rating = "Not Rated Yet";
                        } else {
                            foreach ($subjects['SubjectRate'] as $rate):
                                $rating+=$rate['rating'];
                            endforeach;
                            $avg_rating = round($rating / $votes, 2);
                        }
                        
                        echo number_format($avg_rating,1);
                    ?></span></td>
                    </tr>
                <?php } ?>



                <tr><td id="label">Added by :</td><td><?php echo ucfirst($subjects['User']['username']); ?></td></tr>
                <?php if ($subjects['Subject']['status'] == '1') { ?><tr><td id="label">Inception Date:</td><td><?php $timestamp=strtotime($subjects['Subject']['approved_on']); echo date("Y-m-d",$timestamp);  ?></td></tr><?php } else { ?>
                    <tr><td id="label">Added On:</td><td><?php echo $subjects['Subject']['created']; ?></td></tr><?php } ?>
                <?php
                if ($subjects['Subject']['status'] != '0' && $this->Access->check('Subject', 'create') && !$this->Time->wasWithinLast( "7 days", $lastrated['SubjectRate']['created'] )) {
                    echo $this->Form->create('Subject', array('controller' => 'Subjects', 'action' => 'view'));
                    ?>
                    <tr>
                        <td id="label">Rate It</td>
                        <td><div class="meter-div">
                                <!-- Slider -->
                                <?php echo $this->Form->input('', array('label' => '', 'type' => 'hidden', 'name' => 'subject_id', 'id' => 'subject_id', 'value' => $subjects['Subject']['id'])); ?>


                                <input type="hidden" id="amount" value="70" name="rating" style="border:0; color:#f6931f; font-weight:bold;" />
                                <div id="slider-range-min" style="width:500px;"> </div>
                            </div></td>
                    </tr>
                    <tr><td colspan="2">&nbsp;</td></tr>
                    <tr><td colspan="2">&nbsp;</td></tr>

                    <tr><td colspan="2"><?php echo $this->Form->end(array('label' => 'Rate Now', 'class' => 'mybutton', 'id' => 'rate_subject')); ?></td></tr>


                <?php } ?>

                <td>

                </td>
    </tr>
</table>   
</td>
</tr>

</table>
<script language="javascript">
    $(document).ready(function() {
        $( "#slider-range-min" ).slider({
            range: "min",
            value: $('input[name=rating]').val(),
            min: 0,
            max: 100,
            slide: function( event, ui ) {
                            
                $( ".ui-slider-handle" ).text( ui.value );
				
                //add color class
                if(ui.value<='25'){
                    $( ".ui-slider-handle" ).addClass('low_value');
                }else if(ui.value<='50'){
                    $( ".ui-slider-handle" ).addClass('medium_value');
                }
				
            }
        });
        $( ".ui-slider-handle" ).text($( "#slider-range-min" ).slider( "value" ) );
        //add color class
        if('ui.value'<='25' ){
            $( ".ui-slider-handle" ).addClass('low_value');
                                      
        }else if('ui.value'<='50'){
            $( ".ui-slider-handle" ).addClass('medium_value');
        }
				  
    });
    $('#SubjectAdminAddForm').live('submit',function(){
        $('input[name=rating]').val($( "#slider-range-min" ).slider( "value" ));
         
        
        
    });
    $('#reportImage').live('submit',function(){
        if ($("#report_comment").val().length < 1) {
	    $("#error").show();
	    $.fancybox.resize();
	    return false;
	}
        $.ajax({
                url: "report",
                type: "POST",
                data: {
                    subject_id : <?php echo $subjects['Subject']['id'];?>,
                    type :$(this).attr('title'),
                    comment : $('#report_comment').val(),
                    id :<?php echo $_SESSION['Auth']['User']['id'] ?>
                    },
                dataType: "html",
                async:false,
                success: function(response){
                    $.fancybox(response);
                }
            });
       
         
        return false;
        
    });
        
</script>

<div style="display: none;">
    <div id="inline1" class="report_popup">
        <div id="error" style="background: none repeat scroll 0 0 red;
    color: #FFFFFF;
    display: none;">Please type something </div>
                    <?php

echo $this->Form->create('Subject',array('id'=>'reportImage','title'=>'u'));
echo $this->Form->input('report',array('label'=>'<span style="font-size:18px">Leave a comment</span>','type'=>'textarea','id'=>'report_comment','rows'=>'10','cols'=>60));
echo $this->Form->end(array('label'=>'Report','class'=>'mybutton'));
?>
    </div>
    
    
    
    
</div>
